// pages/myfeedback/myfeedback.js
var util = require("../../utils/util.js")
var api = require("../../utils/api.js")
var app = getApp();
Page({

    /**
     * 页面的初始数据
     */
    data: {
        username: '',
        mobile: '',
        text: '',
        userid: '',
    },
    usernameInput: function(e) {
        this.setData({
            username: e.detail.value
        })
    },
    usermobile: function(e) {
        this.setData({
            mobile: e.detail.value
        })
    },
    usertext: function(e) {
        this.setData({
            text: e.detail.value
        })
    },
    dologin: function() {
        var that = this
        var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(17[0-9]{1}))+\d{8})$/;
        if (that.data.username == '') {
            api.showError("姓名不能为空")
            return;
        }
        if (that.data.mobile == 0 || that.data.mobile == '') {
            api.showError("手机号不能为空")
            return;
        }
        if (!myreg.test(that.data.mobile)) {
            api.showError("手机号输入有误")
            return;
        }

        var data = {
            mobile: that.data.mobile,
            content: that.data.test,
            username: that.data.username,
            name: that.data.username,
            account_id: that.data.userid
        }
        var url = app.u.HOME_URL + app.u.PSY_APPLY
        api.requestUrl(data, url).then(res => {
            api.showError("提交成功")
            setTimeout(function() {
                wx.switchTab({
                    url: '../my/my'
                })
            }, 1000)
        })

    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        var that = this
        wx.getStorage({
            key: 'userInfo',
            success: function(res) {
                that.setData({
                    userid: res.data.id,
                })
            }
        })
 
    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function() {
		wx.showShareMenu({
			withShareTicket: true
		})
    },

})